/*
 * Copyright 2012 Antonio Leiva
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.limecreativelabs.animaciones;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

public class MainActivity extends Activity {
	
	Spinner spinner;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        spinner = (Spinner)findViewById(R.id.spinner);
        
        String[] animations = new String[]{ "Slide in", "Slide out", "fade in", "rotate", "scale" };
        ArrayAdapter<String> adapter0 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, animations);
        adapter0.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
        spinner.setAdapter(adapter0);
        
        Button btn = (Button)findViewById(R.id.animateBtn);
        
        btn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				int sel = spinner.getSelectedItemPosition();
				int anim = 0;
				
				switch (sel) {
				case 0:
					anim = R.anim.slide_in;
					break;
				case 1:
					anim = R.anim.slide_out;
					break;
				case 2:
					anim = R.anim.alpha;
					break;
				case 3:
					anim = R.anim.rotate;
					break;
				case 4:
					anim = R.anim.scale;
					break;
				default:
					break;
				}
				
				Animation slideUpIn = AnimationUtils.loadAnimation(MainActivity.this, anim);
				TextView  tv = (TextView)findViewById(R.id.animated);
		        tv.startAnimation(slideUpIn);				
			}
		});
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    
}
